import 'package:json_annotation/json_annotation.dart';

part 'response.g.dart';

@JsonSerializable(genericArgumentFactories: true)
class ListResponse<T> {
  final int count;
  final List<T> list;

  const ListResponse({required this.count, required this.list});

  factory ListResponse.fromJson(
    Map<String, dynamic> json,
    T Function(dynamic json) fromJsonT,
  ) =>
      _$ListResponseFromJson<T>(json, fromJsonT);

  Map<String, dynamic> toJson(
    Object Function(T value) toJsonT,
  ) =>
      _$ListResponseToJson(this, toJsonT);
}

@JsonSerializable(genericArgumentFactories: true)
class CommonResponse<T> {
  final int code;
  final String? msg;
  final T data;

  const CommonResponse({required this.code, required this.msg,required this.data});

  factory CommonResponse.fromJson(
      Map<String, dynamic> json,
      T Function(dynamic json) fromJsonT,
      ) =>
      _$CommonResponseFromJson<T>(json, fromJsonT);

  Map<String, dynamic> toJson(
      Object Function(T value) toJsonT,
      ) =>
      _$CommonResponseToJson(this, toJsonT);

  bool isSuccessful(){
    return code >= 200 && code <= 299;
  }
}
